# 需要处理目录的绝对路径
import os

from xjlibrary.our_file_dir import BaseDir

FileRoots = [r'E:\样例数据\sipopatent\sipopatent_cover_20180905',
             r'E:\样例数据\sipopatent\sipopatent_cover_20180913',
             r'E:\样例数据\sipopatent\sipopatent_cover_20180918',
             r'E:\样例数据\sipopatent\sipopatent_cover_20180921']


def Main():
    # 先修改文件名
    count = 0
    msg = ""
    with open('./id_abs.txt', mode='w', encoding='utf8') as f:
        for FileRoot in FileRoots:
            for parent, dirnames, filenames in os.walk(FileRoot):
                for filename in filenames:
                    filename = filename.upper()
                    if not filename.endswith('.JPG'):
                        continue
                    count += 1
                    srcFile = os.path.join(parent, filename)
                    srcFile = srcFile.replace("\\","\\\\")
                    app_id = filename.replace(".JPG", "")
                    app_id = "CN{}.{}".format(app_id[:-1], app_id[-1])
                    msg += "{}\t{}\n".format(app_id, srcFile)
                    if count % 10000 == 1:
                        f.write(msg)
                        msg = ""
                        print(count)
        if msg:
            f.write(msg)
    print(count)


Main()
